Note: Use explicit parentheses when there is even the possibility of confusion.
Priority | Operators | Operation | Associativity |
---|---|---|---|
1 | [ ] |
array index | left |
() |
method call | ||
. |
member access | ||
2 | ++ |
pre- or postfix increment | right |
-- |
pre- or postfix decrement | ||
+ - |
unary plus, minus | ||
~ |
bitwise NOT | ||
! |
boolean (logical) NOT | ||
(type) |
type cast | ||
new |
object creation | ||
3 | * / % |
multiplication, division, remainder | left |
4 | + - |
addition, substraction | left |
+ |
string concatenation | ||
5 | << |
signed bit shift left | left |
>> |
signed bit shift right | ||
>>> |
unsigned bit shift right | ||
6 | < <= |
less than, less than or equal to | left |
> >= |
greater than, greater than or equal to | ||
instanceof |
reference test | ||
7 | == |
equal to | left |
!= |
not equal to | ||
8 | & |
bitwise AND | left |
& |
boolean (logical) AND | ||
9 | ^ |
bitwise XOR | left |
^ |
boolean (logical) XOR | ||
10 | | |
bitwise OR | left |
| |
boolean (logical) OR | ||
11 | && |
boolean (logical) AND | left |
12 | || |
boolean (logical) OR | left |
13 | ? : |
conditional | right |
14 | = |
assignment | right |
*= /= += -= %= |
combinated assignment (operation and assignment) |
||
Operators with the same precedence level in an expression are evaluated based on their associativity.
For example, left-associative operators group from left-to-right. Therefore, the expression
x * y % zis equivalent to
(x * y) % z
x = y = 5is evaluated right-to-left :
x = (y = 5)
These are the general categories of operators evaluated from first to last